#include "Stackle_For_Char.c"
#include "sqlink.c"
//对的，注意入栈的是Node*类型
typedef struct Reducer_Link
{
    Node* term_ptr;
    struct Reducer_Link* next;
}Reducer_Link;


typedef struct Stackle_For_Reducer
{
    Reducer_Link* base;
    Reducer_Link* top;
}Stackle_For_Reducer,*Stackle_For_Reducer_Ptr;

Stackle_For_Reducer* Stackle_For_Reducer_Init()
{
    Stackle_For_Reducer* head = (Stackle_For_Reducer_Ptr)malloc(sizeof(Stackle_For_Reducer));
    if(!head)   exit(1);
    head->top = NULL;
    head->base = NULL;
    return head;
}


void Stackle_For_Reducer_Push(Stackle_For_Reducer_Ptr Stack,Node* term_ptr)
{
    if(Stack->base == NULL)
    {
        Stack->top = (Reducer_Link*)malloc(sizeof(Reducer_Link));
        Stack->base = Stack->top;
        Stack->top->next = NULL;
        Stack->top->term_ptr = term_ptr;
    }
    else
    {
        Reducer_Link* temp;
        temp = Stack->top;
        Stack->top = (Reducer_Link*)malloc(sizeof(Reducer_Link));
        temp->next = Stack->top;
        Stack->top->term_ptr = term_ptr;
        Stack->top->next = NULL;
    }
}


void Stackle_For_Reducer_Pop(Stackle_For_Reducer_Ptr Stack)
{
    if(Stack->base == NULL)  exit(1);
    if(Stack->base != NULL)
    {
        if(Stack->base == Stack->top)
        {
            free(Stack->base);
            Stack->base = NULL;
            Stack->top = NULL;
        }
        else
        {
            Reducer_Link* temp;
            temp = Stack->base;
            for(;temp->next != Stack->top;)    temp = temp->next;
            free(Stack->top);
            Stack->top = temp;
            Stack->top->next = NULL;
        }
    }
}

void Print_Stackle_For_Reducer(Stackle_For_Reducer_Ptr Stack)
{
    Reducer_Link* cur = Stack->base;
    for(;cur != NULL;cur = cur->next)
    {
        printf("%d",cur->term_ptr->order);
    }
    printf("%d",cur->term_ptr->order);
}

/*
void main()
{
    Node* head = initList();
    insertNode(head,1,'1','2','3');//1
    insertNode(head,1,'a','b','c');//2
    insertNode(head,1,'z','y','x');//3
    insertNode(head,1,'q','w','e');//4
    insertNode(head,1,'y','x','p');//5
    insertNode(head,1,'p','x','p');//6
    deleteNode(head,3);//删除3
    Node* temp = head->next;
    for(;temp->next != NULL;temp = temp->next)
    {
        printf("%c",temp->exp[0]);
    }
    printf("%c\n",temp->exp[0]);
    
    Stackle_For_Reducer_Ptr Stack_For_Reducer = Stackle_For_Reducer_Init();
    Node* cur;
    for(cur = head->next;cur->next != NULL;cur = cur->next)
    {
        Stackle_For_Reducer_Push(Stack_For_Reducer,cur);
    }
    Stackle_For_Reducer_Push(Stack_For_Reducer,cur);
    Print_Stackle_For_Reducer(Stack_For_Reducer);
    
}
*/